package com.xzc.java8.C_Collect;

import java.util.ArrayList;
import java.util.List;

import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.reducing;

public class DIYTest {

    public static void main(String[] args) {
        List<Apple> list0 = new ArrayList<>();
        Apple a0 = new Apple("a0", "red", 150, 2011);
        Apple a1 = new Apple("a1", "blue", 10, 2012);
        Apple a2 = new Apple("a2", "red", 110, 2011);
        Apple a3 = new Apple("a3", "yellow", 140, 2013);
        list0.add(a0);
        list0.add(a1);
        list0.add(a2);
        list0.add(a3);

        //第1个参数是默认值
        //第2个参数是一个映射，如何将SRC映射为结果集的类型，并在FORK中抽取出来
        //第3个参数是如果将FORK出来的新数据进行JOIN，最后归约成结果集，每JOIN一次就会产生一个新数据
        int out0 = list0.stream().collect(reducing(0, Apple::getWeight, (i, j) -> i + j));
        System.out.println(out0);
    }
}
